package main

type BlockChain struct {
	blocks []*Block
}

//NewBlockChain 构造函数
func NewBlockChain() *BlockChain{
	//需要创建创世块
	return &BlockChain{[]*Block{NewGenesisBlock()}}
}

//AddBlock 交易挖矿
func (bc *BlockChain)AddBlock(data string ){
	//获取前块hash值 5各元素 最新的block[4]
    top :=len(bc.blocks)
    prev :=bc.blocks[top -1].Hash
	//创建一个新区快
	b:=NewBlock(data,prev)
	//加入到区块链中
	bc.blocks =append(bc.blocks,b)
}